package edu.hunau.cxb19.oop.class19;

import java.util.Deque;
import java.util.LinkedList;

import org.junit.Test;

/**
 *
 *@author hb
 *
 * 2020-03-20 15:46:37
 */
public class LinkedTest {
	//Node描述单向链表的一个节点
	class Node{
		 Node next;
		 String data;
		 
		 public Node(String data) {
			 this.data=data;
		 }
		
	}
	
	public void testNode() {
		Node nodeA=new Node("A");
		nodeA.next=new Node("B");
		nodeA.next.next=new Node("C");
	}
	
	
	@Test
	public void testDeque() {
		Deque<String> deque = new LinkedList<String>();
		deque.addFirst("A");
		boolean b1=deque.offerFirst("B");
		deque.addFirst("C");
		System.out.println(deque);//C,B,A
	}
	
	@Test
	public void testStack() {
		Deque<String> stack = new LinkedList<String>();
		stack.push("A");
		stack.push("B");
		stack.push("C");
		System.out.println(stack);//[C, B, A]
		String data = stack.poll();//C出栈
		stack.poll();//B出栈
		System.out.println(stack);//[A]
		stack.peek();//获得栈顶的元素，但是不会将元素弹出
		System.out.println(stack);
	}

}
